package com.squid.cloud.fuel.purchase.web;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSON;
import com.github.pagehelper.PageHelper;
import com.squid.cloud.common.component.SquidRedisTemplate;
import com.squid.cloud.common.component.generaterno.GeneraterNo;
import com.squid.cloud.common.dto.BaseResponseDto;
import com.squid.cloud.model.dao.CodeEntityMapper;
import com.squid.cloud.model.entity.CodeEntity;
import com.squid.cloud.model.entity.CodeEntityExample;

import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

@RestController
public class HelloController {

	private static final Logger log = LoggerFactory.getLogger(HelloController.class);

	@Autowired
	SquidRedisTemplate<String, String> redisTemplate;
	@Autowired
	CodeEntityMapper codeEntityMapper;
	@Autowired
	GeneraterNo generaterNo;

	@SuppressWarnings("rawtypes")
	@ApiOperation(value = "打招呼", notes = "给客户打个招呼")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "name", value = "用户名称", required = true, dataType = "String", paramType = "path") })
	@RequestMapping(value = "/hello", method = RequestMethod.GET)
	public BaseResponseDto sayHello(@RequestParam(name = "name") String name) {
		BaseResponseDto response = new BaseResponseDto();
		response.success();
		log.info("param:name->{}", name);
		CodeEntity codeEntity = codeEntityMapper.selectByPrimaryKey(1l);
		log.info("codeEntity=" + codeEntity);
		log.info("orderNo=" + generaterNo.newOrderNo());

		// 使用分页插件
		PageHelper.startPage(1, 10);
		CodeEntityExample example = new CodeEntityExample();
		List<CodeEntity> codeList = codeEntityMapper.selectByExample(example);
		codeList.forEach(code -> {
			log.info(JSON.toJSONString(code));
		});

		return response;
	}
}